package com.java110.mall.goods.cmd.productCategory;

import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.Environment;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.mall.goods.bmo.mainCategory.IUpdateMainCategoryBMO;
import com.java110.po.mainCategory.MainCategoryPo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;

@Java110Cmd(serviceCode = "productCategory.updateMainCategory")
public class UpdateMainCategoryCmd extends Cmd {



    @Autowired
    private IUpdateMainCategoryBMO updateMainCategoryBMOImpl;
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        Environment.isDevEnv();
        Assert.hasKeyAndValue(reqJson, "categoryName", "请求报文中未包含categoryName");
        Assert.hasKeyAndValue(reqJson, "categoryType", "请求报文中未包含categoryType");
        Assert.hasKeyAndValue(reqJson, "startTime", "请求报文中未包含startTime");
        Assert.hasKeyAndValue(reqJson, "endTime", "请求报文中未包含endTime");
        Assert.hasKeyAndValue(reqJson, "mainCategoryId", "mainCategoryId不能为空");
    }

    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        MainCategoryPo mainCategoryPo = BeanConvertUtil.covertBean(reqJson, MainCategoryPo.class);
        ResponseEntity<String> responseEntity = updateMainCategoryBMOImpl.update(mainCategoryPo);
        context.setResponseEntity(responseEntity);
    }
}
